package nc.ui.arap.flow.dztz;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import nc.ui.arap.service.IRemoteCallItem;
import nc.ui.pub.ClientEnvironment;
import nc.vo.arap.engine.BtnInfoVO;
import nc.vo.arap.engine.FlowInfoVO;
import nc.vo.arap.service.ServiceVO;
import nc.vo.arap.workflow.config.ConfigAgent;
import nc.vo.arap.workflow.config.ConfigCache;
import nc.vo.pub.BusinessException;

public class InitNodeCall implements IRemoteCallItem {

	private String moduleCode;
	public InitNodeCall(String moduleCode) {
		this.moduleCode=moduleCode;
	}
	
	protected ServiceVO serviceVO=null;


	public ServiceVO getServiceVO() {
		if(serviceVO==null){
			serviceVO = new ServiceVO();
			serviceVO.setClassname("nc.itf.arap.pub.IConfigurationServicePublic");
			serviceVO.setMethodname("initNode");
			serviceVO.setParamtype(new Class[] { String.class, String.class });
			serviceVO.setParam(new Object[] {moduleCode,ClientEnvironment.getInstance().getCorporation().getPk_corp()});
			serviceVO.getCode();
		}
		return serviceVO;
	}


	public void setServiceVO(ServiceVO serviceVO) {
		this.serviceVO = serviceVO;
	}


	public void handleResult(Map<String, Object> datas) throws BusinessException {
		List<List<Map<String, ?>>> values = (List<List<Map<String, ?>>>) datas.get(serviceVO.getCode());

		ConfigCache cache = ((ConfigAgent)ConfigAgent.getInstance()).getCache();
		List<Map<String, ?>> buttons = values.get(0);
		List<Map<String, ?>> flows = values.get(1);
		
		
		cache.putButtons(moduleCode, ClientEnvironment.getInstance().getCorporation().getPk_corp(),(Map<String, BtnInfoVO>) buttons.get(0));
		
		for (Iterator iter = flows.iterator(); iter.hasNext();) {
			Map<String, FlowInfoVO> flow = (Map<String, FlowInfoVO>) iter.next();
			if(flow!=null && flow.size()!=0){
				cache.putFlows(flow.values().iterator().next().getNamespace(), flow);
			}
		}
	}

}
